<?php

class ProdutosdestaqueController extends Site_Controller_Action
{

    public function init()
    {
        
    }

    public function indexAction()
    {   
        $this->view->headScript()->appendFile($this->_urlbase.'/public/media/js/view/s_curso.js');
        
        $obj = new Ead_Model_DbTable_Catcurso();
        $this->view->filtro = $obj->fetchAll()->toArray();
        
        
        $where = 'CUR_STAPROM = 1 and CUR_STA = 1 and (CUR_VLD >= "'.date('Y-m-d').'" OR CUR_VLD = "0000-00-00")';
        $obj = new Ead_Model_DbTable_Curso();
        $this->view->result = $obj->fetchAll($where);
        
        $obj = new Ead_Model_DbTable_Catcurso();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['CTC_ID']] = $r['CTC_NOM'];
        
        $this->view->submenu_page = TRUE;
        
    }
    
    public function filtroAction(){
        $this->_helper->layout->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(); 
               
        $where = 'CUR_STAPROM = 1 and CUR_STA = 1 and CUR_VLD >= "'.date('Y-m-d').'" ';
        $filtro = (int)$this->_getParam('filtro', 0);
        if($filtro > 0) $where .= ' and CTC_ID = '.$filtro;
        
        $obj = new Ead_Model_DbTable_Curso();
        $result = $obj->fetchAll($where);
        
        $html =  $this->view->partial('cursos/list-cursos.phtml', array('urlbase' => $this->_urlbase, 'controller' => 'cursos', 'result'=>$result));
        
        echo json_encode(array('ok' => true, 'html' => $html));
    }


}

